<?php


// currently you have to add the ? or & by hand
// maybe automate by having a script check if ? exists.
function PagerBar($pageName, $tnum, $count, $curr, $inc) {
  $maxpage = ceil($count/$inc);
  $currpage = 1+ (($curr > 0) ? $curr/$inc : 0);
  
  if( $curr > 1 ) {
    $page = $curr - $inc;
    $first = "<a href=\"{$pageName}tnum=$tnum&start=0&inc=$inc\">[FIRST]</a>";
    $prev = "<a href=\"{$pageName}tnum=$tnum&start=$page&inc=$inc\">[PREV]</a>";
  } else {
    $prev = ' [Prev] ';
    $first = ' [First Page] ';
  }

  if( $currpage < $maxpage ) {
    $page = $curr + $inc;
    $maxnum = $count - $inc;
    $next = "<a href=\"{$pageName}tnum=$tnum&start=$page&inc=$inc\">[NEXT]</a>";
    $last = "<a href=\"{$pageName}tnum=$tnum&start=$maxnum&inc=$inc\">[LAST]</a>";
  } else {
    $next = ' [NEXT] ';
    $last = ' [LAST] ';
  }
  
  if( $maxpage > 1 ) {
    echo $first . $prev . $nav . $next . $last;
  }
}
?>
